package util;

import game.FullscreenActivity;

import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;


public class Logger {
	private static FullscreenActivity myActivity;
	private static Bundle b;
	public static void setContext(FullscreenActivity c){ myActivity = c; }
	public static final String TAG = "CoM";
	
	private static void queueMessage(String text){
		Message msg = myActivity.handler.obtainMessage();
		if(b==null){b = new Bundle();}
		b.clear();
		b.putString("Text", text);
		msg.setData(b);
		myActivity.handler.sendMessage(msg);
	}
	public static void popUp(String msg){
		if(Looper.getMainLooper().getThread() == Thread.currentThread()) {
			Toast.makeText(myActivity, msg, Toast.LENGTH_SHORT).show();
		}else{
			queueMessage(msg);
		}
	}
	
	
	public static void log(String msg){
		//if(prefs.getBoolean(OptionsActivity.LOG_KEY, OptionsActivity.LOG_KEY_DEF)){
			Log.d(TAG,msg);
		//}	
	}

	public static void log(String tag, String msg){
		//if(prefs.getBoolean(OptionsActivity.LOG_KEY, OptionsActivity.LOG_KEY_DEF)){
			Log.d(tag,msg);
		//}	
	}
	
	public static void e(Exception e){
		Log.e(TAG, e.toString(), e);
	}
}
